#include <iostream> #include <stdio.h> #include <cstring> #include <math.h> #include <algorithm> #define inf 0x3f3f3f3f #define ll long long #define mod 100000007 using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 const int NV = 100005; struct Matrix{ ll v[3][3]; Matrix operator * (const Matrix & b)const{ Matrix tt; for(int i=1;i<=2;i++){ for(int j=1;j<=2;j++){ tt.v[i][j]=(v[i][1] * b.v[1][j] % mod+ v[i][2] * b.v[2][j] % mod)%mod; } } return tt; } }sum[NV<<2]; void PushUp(int rt) { sum[rt]=sum[rt<<1]*sum[rt<<1|1]; } void build(int l,int r,int rt=1) { if (l == r) { sum[rt].v[1][1]=1;sum[rt].v[1][2]=1; sum[rt].v[2][1]=1;sum[rt].v[2][2]=1; return ; } int m = (l + r) >> 1; build(lson); build(rson); PushUp(rt); } void update(int L,int l,int r,int rt,int a,int b) { if (L == l && l == r) { sum[rt].v[a][b] ^= 1; return ; } int m = (l + r) >> 1; if (L <= m) update(L , lson,a,b); else update(L , rson,a,b); PushUp(rt); } Matrix query(int L,int R,int l,int r,int rt=1) { if (L <= l && r <= R) return sum[rt]; int m = (l + r) >> 1; Matrix ret ; ret.v[1][1]=ret.v[2][2]=1; ret.v[1][2]=ret.v[2][1]=0; if (L <= m) ret =ret * query(L , R , lson); if (m < R) ret =ret * query(L , R , rson); return ret; } int m,n; int main() { while(~scanf("%d%d",&n,&m)){ build(1,n); while(m--){ int op; scanf("%d",&op); if(op){ int x,d1,d2; scanf("%d%d%d",&x,&d1,&d2); update(x,1,n,1,d1,d2); } else{ int d,u;Matrix tt; scanf("%d%d",&d,&u); tt=query(d,u-1,1,n); ll ans=0; for(int i=1;i<=2;i++) for(int j=1;j<=2;j++){ ans=(ans+tt.v[i][j])%mod; } printf("%I64d\n",ans); } } } return 0; }
|